package io.renren.modules.app.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.app.entity.BsDishEntityVo;
import io.renren.modules.app.entity.BsOrderdishEntity;
import io.renren.modules.app.service.BsOrderdishService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;




/**
 * 点餐记录表
 *
 */
@RestController
@RequestMapping("tb_bs_orderdish/bsorderdish")
public class BsOrderdishController {
    @Autowired
    private BsOrderdishService bsOrderdishService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("tb_bs_orderdish:bsorderdish:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = bsOrderdishService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("tb_bs_orderdish:bsorderdish:info")
    public R info(@PathVariable("id") Long id){
		BsOrderdishEntity bsOrderdish = bsOrderdishService.getById(id);

        return R.ok().put("bsOrderdish", bsOrderdish);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("tb_bs_orderdish:bsorderdish:save")
    public R save(@RequestBody BsOrderdishEntity bsOrderdish){
        bsOrderdishService.saveOrderDish(bsOrderdish);
		//bsOrderdishService.save(bsOrderdish);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("tb_bs_orderdish:bsorderdish:update")
    public R update(@RequestBody BsOrderdishEntity bsOrderdish){
        bsOrderdishService.updateOrderDish(bsOrderdish);
		//bsOrderdishService.updateById(bsOrderdish);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("tb_bs_orderdish:bsorderdish:delete")
    public R delete(@RequestBody Long[] ids){
		bsOrderdishService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 获取菜品
     */
    @RequestMapping("/getDish")
    public R getDish(){
        List<BsDishEntityVo> list = bsOrderdishService.getDish();
        return R.ok(list);
    }

}
